package com.studyyoun.android.nonghe.home.fragment;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.studyyoun.android.androidcommonbaselibrary.fragment.CommonBaseFragment;
import com.studyyoun.android.androidcommonbaselibrary.okhttp.callback.OkhttpCommonCallBack;
import com.studyyoun.android.androidcommonbaselibrary.okhttp.client.OkhttpCommonClient;
import com.studyyoun.android.androidcommonbaselibrary.utils.LogUtils;
import com.studyyoun.android.androidcommonbaselibrary.utils.ToastUtils;
import com.studyyoun.android.nonghe.R;
import com.studyyoun.android.nonghe.find.WorkClassDetailsActivity;
import com.studyyoun.android.nonghe.home.model.OneClassModel;
import com.studyyoun.android.nonghe.home.model.TwoClassModel;
import com.studyyoun.android.nonghe.http.HttpUrlHelper;
import com.studyyoun.android.nonghe.welcom.CommonUserHelper;
import com.studyyoun.android.nonghe.welcom.activity.LoginActivity;
import com.studyyoun.android.nonghe.welcom.model.UserModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by androidlongs on 2017/8/27.
 * 站在顶峰，看世界
 * 落在谷底，思人生
 */

public class FindFragment extends CommonBaseFragment {

    private LinearLayout mItemChildLayoutMain;
    private List<OneClassModel> mOneClassModelList = new ArrayList<>();
    private LinearLayout userInformationLinearLayout;
    private Button loginButton;
    private TextView mUserCountTextView;
    private TextView mUserNameTextView;

    @Override
    protected int getCommonLayoutId() {
        return R.layout.fragment_find_layout;
    }



    @Override
    protected void commonInitView(View view) {



        mUserNameTextView = view.findViewById(R.id.tv_user_name);
        mUserCountTextView = view.findViewById(R.id.tv_user_count);

        userInformationLinearLayout = view.findViewById(R.id.ll_user_information);
        loginButton = view.findViewById(R.id.bt_logiin);
    }

    @Override
    protected void commonFunction() {

    }

    @Override
    protected void commonDelayFunction() {

        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserModel userModel = CommonUserHelper.getUserModel();
                if (userModel == null||userModel.getData()==null) {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mContext.startActivity(intent);
                }else {
                    CommonUserHelper.exitUser();
                    loginButton.setText("登录");
                    userInformationLinearLayout.setVisibility(View.GONE);
                    ToastUtils.show("已退出登录",mContext);
                }
            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        loadingNetDatasFunction();
    }

    public void loadingNetDatasFunction() {
        UserModel lUserModel = CommonUserHelper.getUserModel();
        if (lUserModel != null && lUserModel.getData() != null) {

            loginButton.setText("退出登录");
            userInformationLinearLayout.setVisibility(View.VISIBLE);

            String lUserName = lUserModel.getData().getUserName();
            if (TextUtils.isEmpty(lUserName)) {
                lUserName = "***";
            }
            mUserNameTextView.setText("姓名 ：" + lUserName);

            String lSfzCode = lUserModel.getData().getSfzCode();
            if (TextUtils.isEmpty(lSfzCode)) {
                lSfzCode = "***";
            }
            mUserCountTextView.setText("身份证号 ：" + lSfzCode);
        } else {
            loginButton.setText("登录");
            userInformationLinearLayout.setVisibility(View.GONE);
            return;
        }

    }



}
